﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HBattle
{
    public abstract class MovingEntity:BaseGameEntity
    {
        public Vector3 Velocity;

        public string Name = "";

        public override string ToString()
        {
            return Name;
        }

        public float Mass = 1.0f;

        public float MaxSpeed = 5.0f;

        public float MaxForce = 1.0f;

        public float MaxTurnRate = 1.0f;

        public float Speed
        {
            get
            {
                return Velocity.magnitude;
            }
        }

        public Vector3 Position
        {
            get
            {
                return CacheTransform.position;
            }
            set
            {
                CacheTransform.position = value;
            }
        }


        private Transform transform;

        public Transform CacheTransform
        {
            get
            {
                return transform;
            }
        }

        protected virtual void GenGameObject()
        {
            GameObject obj = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Cube"));
            transform = obj.transform;
            obj.name = Name;
        }

        public MovingEntity(int id):base(id)
        {
            Name = id.ToString();
            GenGameObject();
        }

        public MovingEntity(int id, string name, float mass, float maxSpeed, float maxForce, float maxTurnRate) : base(id)
        {
            this.Name = id + "-" + name;
            this.Mass = mass;
            this.MaxSpeed = maxSpeed;
            this.MaxForce = maxForce;
            this.MaxTurnRate = maxTurnRate;

            GenGameObject();
        }
    }
}